/*
    BibleNotebook - A bible reader software
    Copyright (C) 2014  Williams Fernando Lopez

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
 */

package com.simplebible.bible.objects;

import java.util.List;

/**
 *
 * @author Williams Lopez
 */
public class Chapter  extends BibleObject{
    
    List<Verse> verses;
    List<Title> titles;

    public List<Verse> getVerses() {
        return verses;
    }

    public void setVerses(List<Verse> verses) {
        this.verses = verses;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        if(getVerses()!=null){
            Title topTitle = getTopTitle();
            if(topTitle!=null){
                sb.append(topTitle);
                sb.append("\n");
            }

            int i =0;
            for(Verse v : verses){
                Title beforeVerse = getTitleBeforeVerse(v.getAbreviation().getVerse());
                if(beforeVerse!=null){
                    sb.append(beforeVerse);
                    sb.append("\n");
                }
                sb.append(v.toString());
                sb.append("\n");
                i++;
            }
        }
        return sb.toString();
    }

    public List<Title> getTitles() {
        return titles;
    }

    public void setTitles(List<Title> titles) {
        this.titles = titles;
    }

    public Title getTopTitle(){
        for(Title t:titles){
            if(t.getPosition().equals("0")){
                return t;
            }
        }
        return null;
    }

    public Title getTitleBeforeVerse(String verse){
        for(Title t:titles){
            if(t.getPosition().equals(verse)){
                return t;
            }
        }
        return null;
    }





    
}
